<?php

namespace App\Http\Controllers\Finance;

use App\Common\SDK\Domain\FenZhangTong;
use App\Common\SDK\Domain\ChinaUms;
use App\Http\Controllers\Controller;
use App\Models\Agent;
use App\Models\AgentRevenue;
use App\Models\AgentTopUpOrder;
use App\Models\DailyReportStatistics;
use App\Models\FinanceSupplier;
use App\Models\PaymentChannelFztwx;
use App\Models\PaymentChannelFztumswx;
use App\Models\PaymentOrder;
use App\Services\AgentRewardRuleSettings;
use App\Services\CacheLockKeyConst;
use App\Services\PaymentService;
use Carbon\Carbon;
use Illuminate\Database\Eloquent\ModelNotFoundException;
use Illuminate\Http\Request;
use Illuminate\Support\Arr;
use Illuminate\Support\Facades\Log;

class UmsNotifyController extends Controller
{
    private $reqData;

    public function __construct(Request $request)
    {
        if (app()->runningInConsole() && app()->environment() === "local"){}else{
            // 校验数据
            $req = $request->all();
            Arr::forget($req, 's');
            ChinaUms::signVerify($req);
            $this->reqData = $req;
            Log::info('接收银联商务回调通知: ' . json_encode($this->reqData));
        }
    }

    /**
     * 杉德微信支付回调
     */
    public function umsWechat()
    {
        if ((new PaymentService())->handleFztPaymentTopUp(
            $this->reqData['merOrderId'],
            Carbon::createFromFormat('Y-m-d H:i:s', $this->reqData['payTime']),
            $this->reqData,
            'umswx'
        )) {
            return $this->response->array([
                'data' => 'SUCCESS'
            ]);
        }


        return $this->response->noContent();
    }
}
